package src.com.hpu.tools;

import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;

public class InternetTools {

	/**
	 * 没有网络
	 */
	public static final int NO_INTERNET=0;
	
	/**
	 * 连接到网络internet
	 */
	public static final int INTERNET=1;
	
	/**
	 * 连接到wifi
	 */
	public static final int WIFI=2;

	/**
	 * 获取网络状态
	 * @param context 上下文
	 * @return 返回常量
	 */
	public static int statusInternet(Context context){
		ConnectivityManager con=(ConnectivityManager)context.getSystemService(Activity.CONNECTIVITY_SERVICE);  
		boolean wifi=con.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();  
		boolean internet=con.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting();
		if(wifi) return WIFI;
		else if(internet) return INTERNET;
		
		return NO_INTERNET;
	}
}
